package leets.leet2265;



public class Solution {
    int res=0;
    public int averageOfSubtree(TreeNode root) {
        after(root);
        return res;
    }
    public NodeItem after(TreeNode root){
        if(root!=null){

            NodeItem item1=after(root.left);

            NodeItem item2=after(root.right);
            int num= item1.num+ item2.num+1;
            int sum= item1.sum+ item2.sum+ root.val;
            if(sum/num== root.val){
                res++;
            }
            return  new NodeItem(num,sum);
        }else {
            return new NodeItem(0,0);
        }
    }

}
class NodeItem{
    int num;
    int sum;

    public NodeItem(int num, int sum) {
        this.num = num;
        this.sum = sum;
    }
}